package cc.wsyw126.java.nowcoder.sword_offer;

import cc.wsyw126.java.lintCode.swap_two_nodes_in_linked_list.ListNode;

import java.util.HashMap;

/**
 * Created by Administrator on 2017/4/18.
 * 一个链表中包含环，请找出该链表的环的入口结点。
 */
public class EntryNodeOfLoop {
    public ListNode EntryNodeOfLoop(ListNode pHead) {
        HashMap<ListNode, Integer> listNodeIntegerHashMap = new HashMap<>();
        while (pHead!=null) {
            if (listNodeIntegerHashMap.get(pHead) == null) {
                listNodeIntegerHashMap.put(pHead,1);
                pHead=pHead.next;
            }else {
                break;
            }
        }
        return pHead;
    }
}
